<!DOCTYPE html>
<!-- Created by 白墨 on 2021/4/17 22:27:31-->
<html lang="zh-cmn-Hans-CN" xmlns:th="http://www.thymeleaf.org">

<head th:replace="admin/_fragments::head(~{::title})">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>博客管理</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
  <link rel="stylesheet" href="../../static/css/me.css">
</head>

<body>
<!-- 导航 -->
<nav th:replace="admin/_fragments::menu(1)" class="ui inverted attached segment">

</nav>


<div class="ui attached pointing menu tm-hf">
  <div class="ui container">
    <div class="right menu" style="margin-right: 150px;">
      <a href="#" th:href="@{/admin/blogs/input}" class="item">发布</a>
      <a href="#" th:href="@{/admin/blogs}" class="blue active item">列表</a>
    </div>
  </div>
</div>
<!-- 中间部分 -->
<div class="m-container m-padded-tb-big">
  <div class="ui container">
    <div class="ui secondary segment form tm">
      <div class="inline fields">
        <div class="field">
          <input type="text" name="title" placeholder="标题">
        </div>

        <div class="field">
          <div class="ui selection dropdown">
            <input type="hidden" name="type.id">
            <i class="dropdown icon"></i>
            <div class="default text">分类</div>
            <div class="menu">
              <div th:each="type:${types}" class="item" data-value="1" th:data-value="${type.id}" th:text="${type.name}">错误日志</div>
            </div>
          </div>
        </div>
        <div class="field">
          <div class="ui checkbox">
            <input type="checkbox" id="recommend" name="recommend">
            <label for="recommend">推荐</label>
          </div>
        </div>
        <div class="field">
          <button type="button" id="search-btn" class="ui mini blue basic button"><i class="search icon"></i>搜索</button>
        </div>
      </div>
    </div>

    <div id="table-container">

      <div class="ui container form" th:classappend="${result!=null?(result?'success':'error'):''}">
        <div class="ui message" th:classappend="${result!=null?(result?'success':'error'):'success'}">
          <i class="close icon"></i>
          <div class="header">提示：</div>
          <p th:text="${message}">恭喜，操作成功！</p>
        </div>

      <table th:fragment="blogList" class="ui compact blue table tm">
        <thead>
        <tr>
          <th></th>
          <th class="four wide center aligned">标题</th>
          <th class="two wide center aligned">类型</th>
          <th class="one wide center aligned">推荐</th>
          <th class="one wide center aligned">状态</th>
          <th class="three wide center aligned">发布时间</th>
          <th class="three wide center aligned">更新时间</th>
          <th class="five wide center aligned">操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="blog,iterStat : ${pageInfo.list}">
          <td th:text="${iterStat.count}">1</td>
          <td><a href="#" th:href="@{/blog/{id}(id=${blog.id})}" th:text="${blog.title}">母猪的产后护理</a></td>
          <td class="two wide center aligned" th:text="${blog.type!=null?blog.type.name:'未分类'}">涨姿势</td>
          <td th:text="${blog.recommend} ? '是' : '否'">是</td>
          <td th:text="${blog.published} ? '发布':'草稿'">发布</td>
          <td th:text="${#dates.format(blog.createTime,'yyyy-MM-dd HH:mm')}">2020-1-20 09:45</td>
          <td th:text="${#dates.format(blog.updateTime,'yyyy-MM-dd HH:mm')}">2020-1-20 09:45</td>
          <td>
            <a href="#" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" class="ui mini blue basic button">编辑</a>
            <a href="#" onclick="return confirm('确定要删除吗？')" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}" class="ui mini red basic button">删除</a>
          </td>
        </tr>
        </tbody>
        <tfoot>
        <tr>
          <th colspan="4">
            <div class="ui mini pagination menu tm-qt" th:if="${pageInfo.pages}>1">
              <a th:href="@{/admin/blogs(pageNum=1)}" class=" item">首页</a>
              <a th:href="@{/admin/blogs(pageNum=${pageInfo.hasPreviousPage}?${pageInfo.prePage}:1)}" class="  item" th:if="${pageInfo.hasPreviousPage}">上一页</a>
              <a th:href="@{/admin/blogs(pageNum=${pageInfo.hasNextPage}?${pageInfo.nextPage}:${pageInfo.pages})}" class=" item" th:if="${pageInfo.hasNextPage}">下一页</a>
              <a th:href="@{/admin/blogs(pageNum=${pageInfo.pages})}" class=" item">尾页</a>
            </div>
          </th >
          <th colspan="4" class="right aligned">
            当前 <span th:text="${pageInfo.pageNum}"></span> 页,总 <span th:text="${pageInfo.pages}"></span> 页,共 <span th:text="${pageInfo.total}"></span> 篇博客
            <a href="#" th:href="@{/admin/blogs/input}" class="ui mini right blue basic button tm-qt">新增</a>
          </th>
        </tr>
        </tfoot>
      </table>
      </div>
    </div>
  </div>
</div>

<br>
<br>

<!-- 底部 -->
<footer th:replace="admin/_fragments::footer" class="ui inverted vertical segment m-padded-tb-massive">

</footer>


<script src="https://lib.baomitu.com/jquery/3.5.1/jquery.js"></script>
<script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>


<script>
  $('.menu.toggle').click(function() {
    $('.m-item').toggleClass('m-mobile-hide');
  });

  $('.ui.dropdown').dropdown({
    on: 'hover'
  });
  //消息提示关闭初始化
  $('.message .close').on('click', function () {
            $(this).closest('.message').transition('fade');
          });

  $('#clear-btn').on('click', function() {
            $('.ui.type.dropdown').dropdown('clear');
          });

  //搜索按钮
  $("#search-btn").click(function () {
    $("#table-container").load("[[@{/admin/blogs/search}]]",{
      "title" : $("[name='title']").val(),
      "type.id" : $("[name='type.id']").val(),
      "recommend" : $("[name='recommend']").prop('checked')
    });

  });
  $('#newblog-container').load("[[@{/footer/newblog}]]");
</script>
</body>

</html>